package com.ruibang.glass.equipment.service.impl.device;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mysql.jdbc.StringUtils;
import com.ruibang.glass.equipment.domain.req.device.CraneReq;
import com.ruibang.glass.equipment.entity.device.Crane;
import com.ruibang.glass.equipment.mapper.device.CraneMapper;
import com.ruibang.glass.equipment.service.CraneService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 起重机械服务类
 * </p>
 *
 * @author mameng
 * @since 2024-03-20
 */
@Slf4j
@Service
public class CraneServiceImpl extends ServiceImpl<CraneMapper, Crane> implements CraneService {
    /**
     * 起重设备列表
     * @param craneReq
     * @return
     */
    @Override
    public IPage<Crane> queryPage(CraneReq craneReq) {
        IPage<Crane> page = baseMapper.queryCraneList(new Page<>(craneReq.getPageNo(), craneReq.getPageSize()), craneReq);
        return page;
    }

    /**
     * 跟新
     * @param elevator
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResultBody updateOrAddById(Crane elevator) {
        if (StringUtils.isNullOrEmpty(elevator.getId())) {
            baseMapper.insert(elevator);
            return ResultBody.success();
        }
        baseMapper.updateById(elevator);
        return ResultBody.success();
    }
}
